@file:Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")

package com.sx.pipeline.ui.setting.profile

import android.app.Application
import com.blankj.utilcode.util.ToastUtils
import com.sx.mvvmlibs.base.BaseViewModel
import com.sx.mvvmlibs.event.SingleLiveEvent
import com.sx.mvvmlibs.http.CommonObserver
import com.sx.mvvmlibs.utils.Logs
import com.sx.mvvmlibs.utils.RxThreadHelper
import com.sx.pipeline.app.model.CYBaseViewModel
import com.sx.pipeline.repos.http.req.AuditTaskDTO
import com.sx.pipeline.repos.http.req.ResetUserDTO
import com.sx.pipeline.repos.http.res.UserInfoVO

/**
 * @Author: YY
 * @Date: 2022/3/7
 * @Description: TODO
 */
class ProfileVM(app: Application) : CYBaseViewModel(app) {

    override fun registerRxBus() {
        super.registerRxBus()
    }


    fun updateUser(headUrl: String,sex: String,userName:String) {
        val dto= ResetUserDTO(headUrl,sex, userName)
        addSubscribe(
            mModel.updateUser(dto)
                .compose(RxThreadHelper.rxSchedulerHelper())
                .subscribeWith(object : CommonObserver<Any, BaseViewModel<*>>
                    (this, true) {
                    override fun onResult(result: Any) {
                        updateUserInfo()
                        ToastUtils.showShort("保存成功")
                        finish()
                    }

                    override fun onFailed(code: Int, msg: String?) {
                        super.onFailed(code, msg)
                        ToastUtils.showShort(msg)
                    }
                })
        )
    }

}